<template>
  <div>
    <el-breadcrumb class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/main' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>新闻中心</el-breadcrumb-item>
    </el-breadcrumb>

    <el-form :inline="true" :model="news" class="demo-form-inline">
      <el-form-item label="新闻名称">
        <el-input v-model="news.newsTitle" placeholder="资讯标题"></el-input>
      </el-form-item>

      <el-form-item label="发布人">
        <el-input v-model="news.createPerson" placeholder="发布人"></el-input>
      </el-form-item>

      <el-form-item label="是否删除" prop="region">
        <el-select v-model="news.isDelete" placeholder="请选择工作经验">
          <el-option label="全部" value=""></el-option>
          <el-option label="删除" value="1"></el-option>
          <el-option label="未删除" value="0"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="getJobFair">查询</el-button>
        <el-button type="primary" icon="el-icon-edit" circle @click="handleAdd"></el-button>
      </el-form-item>
      <el-table
              v-loading="loading"
              :data="pageInfo.list"
              style="width: 1115px"
              :stripe=true
              :border=true
              height="500">
        <el-table-column
                prop="newsTitle"
                label="资讯标题"
                width="350">
        </el-table-column>
        <el-table-column
                prop="createPerson"
                label="发布人"
                width="80">
        </el-table-column>
        <el-table-column
                prop="lookNum"
                label="点击量"
                width="80">
        </el-table-column>
        <el-table-column
                label="发布时间"
                width="180">
          <template slot-scope="scope">
            <span >{{ makeDate(scope.row.createTime)}}</span>
          </template>
        </el-table-column>

        <el-table-column
                label="最新修改时间"
                width="180">
          <template slot-scope="scope">
            <span >{{ makeDate(scope.row.updateTime)}}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="140">
          <template slot-scope="scope">
            <el-button
                    type="success"
                    size="mini"
                    @click="handleUpdate(scope.row.newsId)">编辑
            </el-button>
          </template>
        </el-table-column>
        <el-table-column label="屏蔽/开放">
          <template slot-scope="scope">
            <el-switch
                    @change="deleteNews($event,scope.row.newsId)"
                    v-model="scope.row.isDelete"
                    :inactive-value="1"
                    :active-value="0"
                    active-color="#13ce66"
                    inactive-color="#ff4949">
            </el-switch>
          </template>
        </el-table-column>
      </el-table>
    </el-form>
    <div style="float: right;margin-right: 300px">
      <el-pagination
              background
              layout="prev, pager, next"
              :total="pageInfo.total"
              :page-size="pageInfo.pageSize"
              @current-change="handlePage"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
  import {makeSimpleDate,makeDate} from "../../../common/js/dateformat"

  export default {
    name: "news-list",
    data(){
      return {
        loading:false,
        pageIndex:1,
        pageInfo:{},
        news:{
          newsTitle:'',
          createPerson:'',
          isDelete:''
        }
      }
    },
    created(){
      this.getJobFair();
    },
    methods:{
      getJobFair(){
        this.loading=true;
        this.$ajax.post(this.$config.url + `news/selNews/${this.pageIndex}`,this.news
        ).then(res => {
          this.pageInfo = res.data;
          this.loading = false;
        }).finally(() => {
        })
      },

      handleAdd(){
        this.$router.push("addNews");
        console.log("");
      },
      deleteNews($event,newsId){
        this.$ajax.post(this.$config.url + `news/deleteNews`,{
              "newsId":newsId,
              "isDelete":$event
            }
        ).then(res => {
          if(res.data.message=="succ"){
            this.$message.success("修改成功")
          }else{
            this.$message.error("出错了，修改失败")
          }
          this.getHrList()
        }).finally(() => {
        })
      },
      handleUpdate(newsId){
        this.$router.push({
          path:'UpdateNews',
          query:{newsId:newsId}
        })
      },
      handleDelete(jobFairId){
        console.log(jobFairId);
      },
      makeSimpleDate(date) {
        return makeSimpleDate(date)
      },
      makeDate(date){
        return makeDate(date)
      },

      handlePage(val) {
        //console.log(val)
        this.pageIndex = val
        //加载数据
        this.getJobFair()
      },
    }
  }
</script>

<style scoped>

</style>